package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行DML语句-update(修改)
 */
public class JDBCDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2 通过驱动管理器与数据库建立链接
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        Statement statement = conn.createStatement();
        String sql = "update userinfo " +
                "set password='666666 '" +
                "where username ='张三'";
        int num = statement.executeUpdate(sql);
        if (num > 0){
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
            conn.close();
        }

    }
